﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shopform
{
    public partial class ProjectChooserForm : Form
    {
        private String selected;

        public ProjectChooserForm()
        {
            InitializeComponent();
            initDGV();
        }

        public String getSelectedProjectID()
        {
            return this.selected;
        }

        private void initDGV()
        {
            DataTable dt;
            int isDone = (this.CHBisDone.Checked) ? 1 : 0;
            if (this.TBProjSearch.Text.Length != 0)
            {
                dt = Project.getAllProjectsWithNameLike(this.TBProjSearch.Text, isDone);
            }
            else
            {
               dt = Project.getAllProjects(isDone);
            }

            DGVProjects.DataSource = dt;
            String[] labels = { 
                                "Projekt azonosito", "Ceg Neve", "Projekt nev", "Varos",
                                "Helyszin", "Kapcsolattarto neve", "Datum" 
                              };

            for (int i = 0; i < this.DGVProjects.Columns.Count; ++i)
            {
                this.DGVProjects.Columns[i].HeaderCell.Value = labels[i];
            }

            this.DGVProjects.AutoResizeColumns();
            this.DGVProjects.AutoSizeColumnsMode =
                    DataGridViewAutoSizeColumnsMode.AllCells;
        }

        private void ButtonCancel_Click(object sender, EventArgs e)
        {
            this.selected = null;
            this.Close();
        }

        private void ButtonChoose_Click(object sender, EventArgs e)
        {
            if (this.DGVProjects.Rows.Count == 0)
            {
                MessageBox.Show("Nincs kivalasztva semmi!\n" +
                                "Szukits a filtereken vagy lepj vissza!");
                return;
            }
            this.selected =
                this.DGVProjects.SelectedRows[0].Cells[0].Value.ToString();
            this.Close();
        }

        private void TBProjSearch_TextChanged(object sender, EventArgs e)
        {
            initDGV();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            initDGV();
        }

    }
}